package net.asfun.jvalog.vo;

import static net.asfun.jvalog.common.log.logger;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.asfun.jvalog.entity.Paper;
import net.asfun.jvalog.resource.PaperDao;


public class Site {
	
	private String title;
	private String subtitle;
	private String url;
	private String theme;
	private String version;
	private String keywords;
	private String description;
	private String base;
	private String timezone;
	private String adminUrl;
	private List<Menu> menus;
	
	public void setBase(String base) {
		this.base = base;
	}

	public String getTimezone() {
		return timezone;
	}

	public void setTimezone(String timezone) {
		this.timezone = timezone;
	}

	private static Site instance = new Site();
	
	static {
		reset();
	}
	
	private Site(){}
	
	public static void reset() {
		Blog site = Blog.info();
		instance.title = site.getTitle();
		instance.subtitle = site.getSubtitle();
		instance.url = site.getUrl();
		instance.adminUrl = site.getUrl() + "console/";//TODO 
		instance.theme = site.getTheme();
		instance.version = site.getVersion();
		instance.keywords = site.getKeywords();
		instance.description = site.getDescription();
		instance.base = site.getBase();
		instance.timezone = Setting.TIMEZONE;
		instance.menus = new ArrayList<Menu>();
		Collection<Paper> papers = PaperDao.listPublished(Paper.PAGE_TYPE);
		for( Paper paper : papers ) {
			Page page = new Page(paper);
			Menu menu = new Menu();
			menu.setAlt(page.getExcerpt());
			menu.setName(page.getTitle());
			menu.setUrl(page.getLink());
			instance.menus.add(menu);
		}
		logger.info("*********************reset site info");
	}
	
	public List<Menu> getMenus() {
		return menus;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSubtitle() {
		return subtitle;
	}

	public void setSubtitle(String subtitle) {
		this.subtitle = subtitle;
	}

	public String getUrl() {
		return url;
	}
	
	public String getBase() {
		return base;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getTheme() {
		return theme;
	}

	public void setTheme(String theme) {
		this.theme = theme;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}
	
	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public String getDescription() {
		return description;
	}
	
	public String getAdminUrl() {
		return adminUrl;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public static Site getInstance() {
		return instance;
	}
}
